<template>
  <el-switch
    v-model="Val"
    v-bind="$attrs"
    :disabled="disabled"
    :active-text="activeText"
    :inactive-text="inactiveText"
    :inline-prompt="inlinePrompt"
  />
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
const emit = defineEmits(['update:modelValue'])
const props = defineProps({
  modelValue: {
    type: [Boolean, String, Number],
    default: () => false
  },
  disabled: {
    type: Boolean,
    default: () => false
  },
  activeText: {
    type: String,
    default: () => '是'
  },
  inactiveText: {
    type: String,
    default: () => '否'
  },
  inlinePrompt: {
    type: Boolean,
    default: () => true
  }
})

const Val = ref(props.modelValue)
//监听父组件的值
watch(
  () => props.modelValue,
  () => {
    Val.value = props.modelValue
  }
)

// 通过emit将值传递给父组件
emit('update:modelValue', Val)
</script>
